import axios from 'axios'
class HttpRequest{
  constructor(){
    this.dio = axios.create()
    // 添加拦截器
    
  }
  init(baseURL,connectTimeout,receiveTimeout,headers,interceptors){
    this.dio.defaults.baseURL = baseURL
    this.dio.defaults.timeout= 0  // 请求超时(0 表示无超时时间)
    //this.dio.defaults.receiveTimeout = receiveTimeout // 接受超时
    //this.dio.defaults.headers = headers
    this.CancelToken = axios.CancelToken
    this.source = CancelToken.source()
  }
  setHeaders(headers){
    this.dio.defaults.headers = Object.assign(this.dio.defaults.headers,headers)
    // 将源对象一个个的属性拷贝到目标对象，如果源对象存在于目标对象相同的key，将进行覆盖
  }
  cancelRequests(token){
    token && this.source.cancel("Operation canceled by the user.")
  }
  // 设置鉴权请求头
  setAuthorizationHeader(requestOptions){
    // requestOptions.headers["token"] = this.token;
    return requestOptions
  }
  async get(url,params,options,cancelToken){
    let response = await axios.get(url,{
      params
    })
    return response.data
  }
  post(){

  }
  postForm(){

  }
}

new HttpRequest().init()